﻿using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;

[Serializable]
public class MapLayer {
    private long id;

    private string tag;

    private int index;

    private List<MapObject> mapObjects;

    public MapLayer()
    {
        mapObjects = new List<MapObject>(100);
    }

    public void addMapLine()
    {

    }
    public void addMapMakder()
    {

    }
    public void addMapModel()
    {

    }
    public void addMapPoint()
    {

    }
    public void addMapPolygon(MapPolygon mapPolygon)
    {
        this.mapObjects.Add(mapPolygon);
    }
    public void addMapText()
    {

    }
    /// <summary>
    /// 通过id查询mapobject
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="id"></param>
    /// <returns></returns>
    public T  findMapObjectWithId<T>(int id) where T :MapObject
    {
        foreach(MapObject mo in mapObjects)
        {
            if (mo.Id == id)
            {
                return (T)mo;
            }
        }
        return default(T);
    }
    /// <summary>
    /// 通过tag查询
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="tag"></param>
    /// <returns></returns>
    public T findMapObjectWithTag<T>(String tag) where T : MapObject
    {
        foreach (MapObject mo in mapObjects)
        {
            if (mo.Tag.Equals(tag))
            {
                return (T)mo;
            }
        }
        return default(T);
    }
    public List<MapObject> MapObjects
        {
            get
            {
                return mapObjects;
            }

            set
            {
                mapObjects = value;
            }
        }

    public long Id
    {
        get
        {
            return id;
        }

        set
        {
            id = value;
        }
    }

    public string Tag
    {
        get
        {
            return tag;
        }

        set
        {
            tag = value;
        }
    }

    public int Index
    {
        get
        {
            return index;
        }

        set
        {
            index = value;
        }
    }
}
